package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.SmSModel;


/**
 * Created by qi.wang on 2017/5/4.
 */

public class TimeLineAdapter extends BaseAdapter {
    private Context context;
    private List<SmSModel.ExpressBean.TracesBean> list;
    private LayoutInflater inflater;

    public TimeLineAdapter(Context context, List<SmSModel.ExpressBean.TracesBean> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        TimeLineHolder viewHolder = null;
        if (convertView == null) {
            inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.itemtimeline, null);
            viewHolder = new TimeLineHolder();
            viewHolder.view0= (View) convertView.findViewById(R.id.view_0);
            viewHolder.image= (ImageView) convertView.findViewById(R.id.image);
            viewHolder.title = (TextView) convertView.findViewById(R.id.title);
            viewHolder.time = (TextView) convertView.findViewById(R.id.time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (TimeLineHolder) convertView.getTag();
        }

        String titleStr = list.get(position).getAcceptStation().toString();
        String timeStr = list.get(position).getAcceptTime().toString();
        viewHolder.title.setText(titleStr);
        viewHolder.time.setText(timeStr);
        if(position==0){
            viewHolder.image.setImageResource(R.mipmap.logistics);
            viewHolder.title.setTextColor(Color.parseColor("#fe9c00"));
            viewHolder.time.setTextColor(Color.parseColor("#fe9c00"));
        }else{
            viewHolder.image.setImageResource(R.mipmap.logistics_default);
            viewHolder.title.setTextColor(Color.parseColor("#777777"));
            viewHolder.time.setTextColor(Color.parseColor("#777777"));
        }



        return convertView;

    }

    static class TimeLineHolder{
        private TextView title,time;
        private View view0;
        private ImageView image;
    }

}
